package c.h.a.j0;

import android.annotation.SuppressLint;
import android.graphics.drawable.Drawable;
import android.location.GnssStatus;
import android.location.GnssStatus.Callback;
import android.location.GpsStatus;
import android.location.GpsStatus.Listener;
import android.location.GpsStatus.NmeaListener;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.location.OnNmeaMessageListener;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import c.h.a.b0.o;
import c.h.a.d0.e;
import c.h.a.m0.h;
import com.liuzh.deviceinfo.DeviceInfoApp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/* compiled from: TabGPS */
public class q0 extends h0 {
    public static final /* synthetic */ int n0 = 0;
    public LocationManager W;
    public Callback X;
    public Listener Y;
    public GpsStatus Z;
    public GnssStatus b0;
    public OnNmeaMessageListener c0;
    public NmeaListener d0;
    public LocationListener e0;
    public View f0;
    public LinearLayout g0;
    public Map<Integer, List<e>> h0 = new HashMap();
    public Map<Integer, d> i0 = new HashMap();
    public c j0;
    public Location k0;
    public FrameLayout l0;
    public String m0;

    /* compiled from: TabGPS */
    public class a implements LocationListener {
        public void onLocationChanged(Location location) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("onLocationChanged , location = ");
            stringBuilder.append(location);
            stringBuilder.toString();
            if (!q0.this.m0()) {
                q0 q0Var = q0.this;
                q0Var.k0 = location;
                c cVar = q0Var.j0;
                if (cVar != null) {
                    cVar.a(location);
                    q0 q0Var2 = q0.this;
                    cVar = q0Var2.j0;
                    cVar.h.setText(q0Var2.m0);
                }
            }
        }

        public void onProviderDisabled(String str) {
        }

        public void onProviderEnabled(String str) {
        }

        public void onStatusChanged(String str, int i, Bundle bundle) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("onStatusChanged  provider = ");
            stringBuilder.append(str);
            stringBuilder.append(", status = ");
            stringBuilder.append(i);
            stringBuilder.append(", extras = ");
            stringBuilder.append(bundle);
            stringBuilder.toString();
        }
    }

    /* compiled from: TabGPS */
    public class b implements Runnable {
        public final /* synthetic */ LayoutInflater a;

        /* compiled from: TabGPS */
        public class a implements Runnable {
            public final /* synthetic */ View a;
            public final /* synthetic */ c b;

            public a(View view, c cVar) {
                this.a = view;
                this.b = cVar;
            }

            public void run() {
                q0 q0Var = q0.this;
                int i = q0.n0;
                if (!q0Var.m0()) {
                    q0.this.l0.setVisibility(0);
                    q0.this.l0.addView(this.a);
                    q0Var = q0.this;
                    c cVar = this.b;
                    q0Var.j0 = cVar;
                    cVar.a(q0Var.k0);
                    q0Var = q0.this;
                    cVar = q0Var.j0;
                    cVar.h.setText(q0Var.m0);
                }
            }
        }

        public b(LayoutInflater layoutInflater) {
            this.a = layoutInflater;
        }

        public d a(int i) {
            return new d(i, this.a.inflate(2131492991, q0.this.g0, false));
        }

        public void run() {
            c.h.a.m0.p.a.b(new o(this, a(2), a(0), a(4), a(1), a(3), a(5), this.a));
            View inflate = this.a.inflate(2131492923, q0.this.l0, false);
            c.h.a.m0.p.a.b(new a(inflate, new c(inflate)));
        }
    }

    /* compiled from: TabGPS */
    public static class c {
        public final TextView a;
        public final TextView b;
        public final TextView c;
        public final TextView d;
        public final TextView e;
        public final TextView f;
        public final TextView g;
        public final TextView h;
        public final TextView i;
        public final TextView j;
        public final TextView k;
        public final TextView l;
        public final TextView m;

        public c(View view) {
            this.a = (TextView) view.findViewById(2131297317);
            this.b = (TextView) view.findViewById(2131297318);
            this.c = (TextView) view.findViewById(2131297312);
            this.d = (TextView) view.findViewById(2131297321);
            this.e = (TextView) view.findViewById(2131297322);
            TextView textView = (TextView) view.findViewById(2131297323);
            this.f = textView;
            this.g = (TextView) view.findViewById(2131297319);
            this.h = (TextView) view.findViewById(2131297324);
            this.i = (TextView) view.findViewById(2131297316);
            this.j = (TextView) view.findViewById(2131297315);
            this.k = (TextView) view.findViewById(2131297320);
            this.l = (TextView) view.findViewById(2131297313);
            TextView textView2 = (TextView) view.findViewById(2131297314);
            this.m = textView2;
            if (!h.c) {
                ((View) textView.getParent()).setVisibility(8);
                ((View) textView2.getParent()).setVisibility(8);
            }
        }

        @SuppressLint({"SetTextI18n"})
        public void a(Location location) {
            if (location != null) {
                TextView textView = this.b;
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append(location.getLongitude());
                stringBuilder.append(DeviceInfoApp.d(2131689788));
                textView.setText(stringBuilder.toString());
                textView = this.a;
                stringBuilder = new StringBuilder();
                stringBuilder.append(location.getLatitude());
                stringBuilder.append(DeviceInfoApp.d(2131689788));
                textView.setText(stringBuilder.toString());
                textView = this.c;
                stringBuilder = new StringBuilder();
                stringBuilder.append(b(location.getAltitude()));
                stringBuilder.append(DeviceInfoApp.d(2131690059));
                textView.setText(stringBuilder.toString());
                textView = this.e;
                stringBuilder = new StringBuilder();
                stringBuilder.append(b((double) location.getSpeed()));
                stringBuilder.append(DeviceInfoApp.d(2131690081));
                textView.setText(stringBuilder.toString());
                String str = "";
                if (location.hasBearing()) {
                    textView = this.l;
                    StringBuilder stringBuilder2 = new StringBuilder();
                    stringBuilder2.append(b((double) location.getBearing()));
                    stringBuilder2.append(DeviceInfoApp.d(2131689788));
                    textView.setText(stringBuilder2.toString());
                } else {
                    this.l.setText(str);
                }
                Object obj = 1;
                boolean z = h.c;
                if (z && location.hasVerticalAccuracy() && location.hasAccuracy()) {
                    String b = b((double) location.getAccuracy());
                    String b2 = b((double) location.getVerticalAccuracyMeters());
                    TextView textView2 = this.j;
                    StringBuilder j = c.b.a.a.a.j(b, " / ", b2);
                    j.append(DeviceInfoApp.d(2131690059));
                    textView2.setText(j.toString());
                    obj = null;
                }
                if (obj != null) {
                    if (location.hasAccuracy()) {
                        textView = this.j;
                        stringBuilder = new StringBuilder();
                        stringBuilder.append(b((double) location.getAccuracy()));
                        stringBuilder.append(" / -");
                        stringBuilder.append(DeviceInfoApp.d(2131690059));
                        textView.setText(stringBuilder.toString());
                    } else {
                        this.j.setText(str);
                    }
                }
                if (z) {
                    if (location.hasSpeedAccuracy()) {
                        textView = this.f;
                        StringBuilder stringBuilder3 = new StringBuilder();
                        stringBuilder3.append(b((double) location.getSpeedAccuracyMetersPerSecond()));
                        stringBuilder3.append(DeviceInfoApp.d(2131690081));
                        textView.setText(stringBuilder3.toString());
                    } else {
                        this.f.setText(2131690514);
                    }
                    if (location.hasBearingAccuracy()) {
                        textView = this.m;
                        stringBuilder = new StringBuilder();
                        stringBuilder.append(b((double) location.getBearingAccuracyDegrees()));
                        stringBuilder.append(DeviceInfoApp.d(2131689788));
                        textView.setText(stringBuilder.toString());
                    } else {
                        this.m.setText(2131690514);
                    }
                }
            }
        }

        public String b(double d) {
            return String.format(Locale.US, "%.2f", new Object[]{Double.valueOf(d)});
        }
    }

    /* compiled from: TabGPS */
    public static class d {
        public final TextView a;
        public final TextView b;
        public final View c;
        public final ImageView d;

        public d(int i, View view) {
            CharSequence d;
            this.c = view;
            TextView textView = (TextView) view.findViewById(2131297270);
            this.a = textView;
            this.b = (TextView) view.findViewById(2131297267);
            ImageView imageView = (ImageView) view.findViewById(2131296627);
            this.d = imageView;
            Drawable drawable = null;
            switch (i) {
                case 0:
                    d = DeviceInfoApp.d(2131690249);
                    drawable = DeviceInfoApp.a(2131231032);
                    break;
                case 1:
                    d = DeviceInfoApp.d(2131690248);
                    drawable = DeviceInfoApp.a(2131231031);
                    break;
                case 2:
                    d = DeviceInfoApp.d(2131690244);
                    drawable = DeviceInfoApp.a(2131231026);
                    break;
                case 3:
                    d = DeviceInfoApp.d(2131690252);
                    drawable = DeviceInfoApp.a(2131231030);
                    break;
                case 4:
                    d = DeviceInfoApp.d(2131690247);
                    drawable = DeviceInfoApp.a(2131231027);
                    break;
                case 5:
                    d = DeviceInfoApp.d(2131690250);
                    drawable = DeviceInfoApp.a(2131231029);
                    break;
                case 6:
                    d = DeviceInfoApp.d(2131690253);
                    break;
                default:
                    d = DeviceInfoApp.d(2131690514);
                    break;
            }
            textView.setText(d);
            imageView.setImageDrawable(drawable);
        }
    }

    public static void s0(q0 q0Var) {
        if (!q0Var.m0() && !q0Var.i0.isEmpty()) {
            int i;
            Iterator it = q0Var.i0.keySet().iterator();
            while (true) {
                i = 0;
                if (!it.hasNext()) {
                    break;
                }
                Integer num = (Integer) it.next();
                List list = (List) q0Var.h0.get(num);
                d dVar = (d) q0Var.i0.get(num);
                if (dVar != null) {
                    TextView textView = dVar.b;
                    Object[] objArr = new Object[1];
                    objArr[0] = Integer.valueOf(list == null ? 0 : list.size());
                    textView.setText(DeviceInfoApp.c.getString(2131690140, objArr));
                }
            }
            c cVar = q0Var.j0;
            if (cVar != null) {
                Iterator it2 = new ArrayList(q0Var.h0.values()).iterator();
                while (it2.hasNext()) {
                    List list2 = (List) it2.next();
                    if (list2 != null) {
                        i += list2.size();
                    }
                }
                cVar.k.setText(String.valueOf(i));
            }
        }
    }

    public static void t0(q0 q0Var, int i) {
        if (!q0Var.m0()) {
            if (i == 0) {
                q0Var.m0 = "";
            } else {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append(TimeUnit.MILLISECONDS.toSeconds((long) i));
                stringBuilder.append(" sec");
                q0Var.m0 = stringBuilder.toString();
            }
            c cVar = q0Var.j0;
            if (cVar != null) {
                cVar.h.setText(q0Var.m0);
            }
        }
    }

    public void E(Bundle bundle) {
        super.E(bundle);
        v0();
    }

    public View G(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View view = this.f0;
        if (view != null) {
            return view;
        }
        View inflate = layoutInflater.inflate(2131493055, viewGroup, false);
        this.f0 = inflate;
        this.g0 = (LinearLayout) inflate.findViewById(2131296849);
        this.l0 = (FrameLayout) this.f0.findViewById(2131296504);
        AsyncTask.execute(new b(layoutInflater));
        return this.f0;
    }

    public void H() {
        this.E = true;
        LocationManager locationManager = this.W;
        if (locationManager != null) {
            LocationListener locationListener = this.e0;
            if (locationListener != null) {
                locationManager.removeUpdates(locationListener);
            }
            if (h.d) {
                Callback callback = this.X;
                if (callback != null) {
                    this.W.unregisterGnssStatusCallback(callback);
                    return;
                }
                return;
            }
            Listener listener = this.Y;
            if (listener != null) {
                this.W.removeGpsStatusListener(listener);
            }
            if (this.d0 != null) {
                try {
                    LocationManager.class.getMethod("removeNmeaListener", new Class[]{NmeaListener.class}).invoke(this.W, new Object[]{this.d0});
                } catch (Exception unused) {
                }
            }
        }
    }

    public void O(int i, String[] strArr, int[] iArr) {
        if (i == 1) {
            if (c.h.a.e0.a.f(iArr)) {
                x0();
                v0();
            } else if (!c.h.a.e0.a.d(this, "android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION")) {
                o.r0(h(), 2131690076, 2131690437);
            }
        }
    }

    public void P() {
        this.E = true;
        x0();
        if (this.W == null) {
            v0();
        }
    }

    public String r0() {
        return DeviceInfoApp.d(2131690436);
    }

    public final boolean u0() {
        return c.h.a.e0.a.b(Z(), "android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_COARSE_LOCATION");
    }

    @SuppressLint({"MissingPermission"})
    public final void v0() {
        if (u0() && this.W == null) {
            LocationProvider provider;
            LocationManager locationManager = (LocationManager) Z().getSystemService("location");
            this.W = locationManager;
            LocationProvider locationProvider = null;
            if (locationManager != null) {
                locationProvider = locationManager.getProvider("gps");
                provider = this.W.getProvider("network");
            } else {
                provider = null;
            }
            LocationManager locationManager2 = this.W;
            if (locationManager2 == null || locationProvider == null) {
                Toast.makeText(Z(), x(2131689951), 0).show();
                return;
            }
            this.e0 = new a();
            locationManager2.requestLocationUpdates(locationProvider.getName(), 1000, 1.0f, this.e0);
            if (provider != null) {
                this.W.requestLocationUpdates(provider.getName(), 1000, 1.0f, this.e0);
            }
            if (h.d) {
                s0 s0Var = new s0(this);
                this.X = s0Var;
                this.W.registerGnssStatusCallback(s0Var);
                if (this.c0 == null) {
                    this.c0 = new q(this);
                }
                this.W.addNmeaListener(this.c0);
            } else {
                t0 t0Var = new t0(this);
                this.Y = t0Var;
                this.W.addGpsStatusListener(t0Var);
                if (this.d0 == null) {
                    this.d0 = new r0(this);
                }
                try {
                    LocationManager.class.getMethod("addNmeaListener", new Class[]{NmeaListener.class}).invoke(this.W, new Object[]{this.d0});
                } catch (Exception unused) {
                }
            }
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:28:0x0079  */
    /* JADX WARNING: Removed duplicated region for block: B:27:0x0055  */
    /* JADX WARNING: No exception handlers in catch block: Catch:{  } */
    public final void w0(java.lang.String r14) {
        /*
        r13 = this;
        r0 = r13.m0();
        if (r0 == 0) goto L_0x0007;
    L_0x0006:
        return;
    L_0x0007:
        r0 = r13.j0;
        if (r0 == 0) goto L_0x0116;
    L_0x000b:
        java.util.Objects.requireNonNull(r0);
        r1 = "$GPGGA";
        r2 = r14.startsWith(r1);
        r3 = "$GNGGA";
        r4 = "$GNGNS";
        r5 = 0;
        r6 = ",";
        if (r2 != 0) goto L_0x0029;
    L_0x001d:
        r2 = r14.startsWith(r4);
        if (r2 != 0) goto L_0x0029;
    L_0x0023:
        r2 = r14.startsWith(r3);
        if (r2 == 0) goto L_0x0080;
    L_0x0029:
        r2 = r14.split(r6);
        r1 = r14.startsWith(r1);
        if (r1 != 0) goto L_0x003f;
    L_0x0033:
        r1 = r14.startsWith(r4);
        if (r1 != 0) goto L_0x003f;
    L_0x0039:
        r1 = r14.startsWith(r3);
        if (r1 == 0) goto L_0x0052;
    L_0x003f:
        r1 = 9;
        r1 = r2[r1];	 Catch:{ ArrayIndexOutOfBoundsException -> 0x0052 }
        r2 = android.text.TextUtils.isEmpty(r1);
        if (r2 != 0) goto L_0x0052;
    L_0x0049:
        r1 = java.lang.Double.parseDouble(r1);	 Catch:{  }
        r1 = java.lang.Double.valueOf(r1);	 Catch:{  }
        goto L_0x0053;
    L_0x0052:
        r1 = r5;
    L_0x0053:
        if (r1 == 0) goto L_0x0079;
    L_0x0055:
        r2 = r0.d;
        r3 = new java.lang.StringBuilder;
        r3.<init>();
        r7 = r1.doubleValue();
        r1 = r0.b(r7);
        r3.append(r1);
        r1 = 2131690059; // 0x7f0f024b float:1.900915E38 double:1.0531948257E-314;
        r1 = com.liuzh.deviceinfo.DeviceInfoApp.d(r1);
        r3.append(r1);
        r1 = r3.toString();
        r2.setText(r1);
        goto L_0x0080;
    L_0x0079:
        r1 = r0.d;
        r2 = "";
        r1.setText(r2);
    L_0x0080:
        r1 = "$GNGSA";
        r2 = r14.startsWith(r1);
        r3 = "$GPGSA";
        if (r2 != 0) goto L_0x0090;
    L_0x008a:
        r2 = r14.startsWith(r3);
        if (r2 == 0) goto L_0x0116;
    L_0x0090:
        r2 = r14.split(r6);
        r1 = r14.startsWith(r1);
        if (r1 != 0) goto L_0x00a0;
    L_0x009a:
        r14 = r14.startsWith(r3);
        if (r14 == 0) goto L_0x00e4;
    L_0x00a0:
        r14 = 15;
        r14 = r2[r14];	 Catch:{ ArrayIndexOutOfBoundsException -> 0x00e3 }
        r1 = 16;
        r1 = r2[r1];	 Catch:{ ArrayIndexOutOfBoundsException -> 0x00e3 }
        r3 = 17;
        r2 = r2[r3];	 Catch:{ ArrayIndexOutOfBoundsException -> 0x00e3 }
        r3 = "*";
        r3 = r2.contains(r3);
        if (r3 == 0) goto L_0x00bd;
    L_0x00b4:
        r3 = "\\*";
        r2 = r2.split(r3);
        r3 = 0;
        r2 = r2[r3];
    L_0x00bd:
        r3 = android.text.TextUtils.isEmpty(r14);
        if (r3 != 0) goto L_0x00e4;
    L_0x00c3:
        r3 = android.text.TextUtils.isEmpty(r1);
        if (r3 != 0) goto L_0x00e4;
    L_0x00c9:
        r3 = android.text.TextUtils.isEmpty(r2);
        if (r3 != 0) goto L_0x00e4;
    L_0x00cf:
        r3 = new c.h.a.m0.q.a;	 Catch:{  }
        r7 = java.lang.Double.parseDouble(r14);	 Catch:{  }
        r9 = java.lang.Double.parseDouble(r1);	 Catch:{  }
        r11 = java.lang.Double.parseDouble(r2);	 Catch:{  }
        r6 = r3;
        r6.m2084init(r7, r9, r11);	 Catch:{  }
        r5 = r3;
        goto L_0x00e4;
    L_0x00e4:
        if (r5 == 0) goto L_0x0116;
    L_0x00e6:
        r14 = r0.g;
        r1 = r5.a;
        r1 = r0.b(r1);
        r14.setText(r1);
        r14 = r0.i;
        r1 = new java.lang.StringBuilder;
        r1.<init>();
        r2 = r5.b;
        r2 = r0.b(r2);
        r1.append(r2);
        r2 = "/";
        r1.append(r2);
        r2 = r5.c;
        r0 = r0.b(r2);
        r1.append(r0);
        r0 = r1.toString();
        r14.setText(r0);
    L_0x0116:
        return;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.h.a.j0.q0.w0(java.lang.String):void");
    }

    public final void x0() {
        if (!m0() && this.f0 != null) {
            if (u0()) {
                this.f0.findViewById(2131296793).setVisibility(8);
            } else {
                this.f0.findViewById(2131296793).setVisibility(0);
                this.f0.findViewById(2131296318).setOnClickListener(new r(this));
            }
        }
    }
}
